package com.yenlien.traceyun.control.controller;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.control.entity.Banner;
import com.yenlien.traceyun.control.service.BannerService;
import com.yenlien.traceyun.webase.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 广告控制层
 *
 * @author aaa
 */
@RestController
@RequestMapping("/banner")
public class BannerController extends BaseController {
    @Autowired
    private BannerService bannerService;

    //广告列表
    @RequestMapping(value = "/findByList", method = RequestMethod.POST)
    public Object findByList(@RequestBody JSONObject params) {
        Banner banner = new Banner();
        banner.setProjectName(params.getString("searchName"));
        banner.setType(params.getString("searchName"));
        return buildPage(bannerService.findByList(banner));
    }

    //新增广告
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Object save(@RequestBody Banner banner) {
        bannerService.save(banner);
        return success("success");
    }

    //根据ID查询广告详情

    @RequestMapping(value = "/findById/{id}", method = RequestMethod.GET)
    public Object findById(@PathVariable("id") String id) {
        return success(bannerService.findById(id));
    }
}
